package com.base

import android.content.Context
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.viewbinding.ViewBinding
import com.event.MessageEvent
import org.greenrobot.eventbus.EventBus
import org.greenrobot.eventbus.Subscribe

abstract class BaseFragment<T : ViewBinding> :Fragment() {
    lateinit var binding: T
    val dataCenter = DataCenter.instance
    val deviceCenter = DeviceCenter.instance
    abstract fun getViewBinding(): T
    abstract fun createView()
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding=getViewBinding()
        EventBus.getDefault().register(this)
    }
    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        return binding.root
    }
    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        createView()
    }
    abstract fun refreshUI()
    @Subscribe
    fun onMessageEvent(event: MessageEvent) {}
    override fun onDestroy() {
        EventBus.getDefault().unregister(this)
        super.onDestroy()
    }
}